<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>越过障碍</title>
    <style>
        #main{
            position: relative;
            width: 500px;
            height: 300px;
            background-color: #666;
            margin: 200px auto;
            overflow: hidden;
        }
        .figure{
            position:absolute;
            bottom:0px;
            width: 20px;
            height: 40px;
            background-color: aqua;
            
        }
        .barrier{
            position: absolute;
            bottom: 0px;
            right: 0px;
            width: 20px;
            height: 30px;
            background-color: red;
            animation: barrierFrames 1.7s linear infinite;
        }
        .active{
            animation: figureFrames .5s linear;
        }
        @keyframes barrierFrames {
            0%{
                right: 0px;
            }
            100%{
                right: 500px;
            }
        }
        @keyframes figureFrames {
            0%{
                transform: translateY(0px);
            }
            50%{
                transform: translateY(-80px);
            }
            100%{
                transform: translateY(0px);
            }
        }
    </style>
</head>
<body>
    <div id="main">
        <div class="figure"></div>
        <div class="barrier"></div>
    </div>
</body>

<script>
    let figure = document.querySelector('.figure')
    window.addEventListener('keydown',event=>{
        if(event.keyCode == 38){
            figure.classList.add('active')
            setTimeout(()=>{
                figure.classList.remove('active')
            },700)
        }
    })
</script>
</html>